﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using RobotBattle2.Scripting;
using Microsoft.Practices.ServiceLocation;

namespace RobotBattle2 {
	public sealed class Game {
		public ReadOnlyCollection<Robot> Robots { get { return m_Robots.AsReadOnly(); } }
		private List<Robot> m_Robots = new List<Robot>();

		public ReadOnlyCollection<ScriptRunnerBase> Scripts { get { return m_Scripts.AsReadOnly(); } }
		private List<ScriptRunnerBase> m_Scripts = new List<ScriptRunnerBase>();

		public void AddRobot(Script script) {
			var runner = ServiceLocator
				.Current
				.GetInstance<ScriptRunnerFactory>()
				.Create(script);
			var robot = new Robot();
			runner.Robot = robot;
			m_Robots.Add(robot);
			m_Scripts.Add(runner);
		}

		public void RunTurn() {
			foreach (var item in m_Scripts) {
				item.RunTurn();
			}
		}
	}
}
